<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
            json是一种常用的数据交互格式
            json的语法：
            1、json的格式：对象和数组
            对象：{key:value,key:value,...}
            数组：[值1,值2,..]
            2、json的解析
            对象：对象.key
            数组：数组[下标]
        */
      var person = {
        name: "张小明",
        age: 20,
        girlFriend: { name: "铁铃", age: 23 },
        foods: ["苹果", "香蕉", "橘子", "葡萄"],
        pets: [
          { petName: "大黄", petType: "dog" },
          { petName: "小花", petType: "cat" },
        ],
      };
      //获取张小明的girlFriend的信息
      console.log(person.girlFriend.name+","+person.girlFriend.age);
      //获取张小明的pets信息
      var pets = person.pets;
      for (let i = 0; i < pets.length; i++) {
        console.log(pets[i].petName + "," + pets[i].petType);
      }
    </script>
  </body>
</html>
